package com.tengfei.experiment2_3;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tengfei.experiment2_3.adapter.ClassroomBuildingAdapter;
import com.tengfei.experiment2_3.pojo.ClassroomBuilding;

import java.util.ArrayList;

public class ListView4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view2);


        ArrayList<ClassroomBuilding> classroomBuildings = new ArrayList<>();
        classroomBuildings.add(new ClassroomBuilding("-==选择教室==-", "", ""));
        classroomBuildings.add(new ClassroomBuilding("文友楼", "510", "多媒体"));
        classroomBuildings.add(new ClassroomBuilding("文友楼", "618", "多媒体"));
        classroomBuildings.add(new ClassroomBuilding("香远楼", "210", "普通"));
        classroomBuildings.add(new ClassroomBuilding("实验楼", "602", "计算机实验室"));
        ListView lv = findViewById(R.id.lv_contact);
        lv.setAdapter(new ClassroomBuildingAdapter(this,classroomBuildings));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ClassroomBuilding item=(ClassroomBuilding) lv.getItemAtPosition(position);
                Toast.makeText(ListView4Activity.this,item.toString(),Toast.LENGTH_SHORT).show();

            }
        });
    }
}